using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Metadata.Entity.DataModel;
using T.FAS.Runtime.StateMachine.SPI;

namespace T.FAS.Runtime.StateMachine.Engine
{
    internal class DefaultActionProcess : IActionProcess
    {
        public const string CSTKEY = "Default";

        public string Key => CSTKEY;

        public string Description => "将目标对象数据设置为默认值。";

        public List<ParamInfo> NeedParamInfo => null;

        public TRecord Do(TRecord record, TAction action, StateMachineMetadata metadata, Dictionary<string, object> extParams = null)
        {
            if (record == null || action == null || string.IsNullOrEmpty(action.Target))
                return record;
            var target = action.Target;
            if (record.GetDynamicMemberNames().Contains(target, StringComparer.OrdinalIgnoreCase) == false)
                throw new Exception(CommonStringClass.DefaultActionProcess_Do+ target);
            var data = record.GetValue(target);
            if (data == null)
                return record;
#warning 需要对接CDO的默认值字段设置
            return record;
        }
    }
}
